package stack;

import java.util.Stack;

public class p232 {
    public static void main(String[] args) {
        MyQueue myQueue=new MyQueue();
        myQueue.push(1);
        myQueue.push(2);
        System.out.println(myQueue.peek());
        System.out.println(myQueue.pop());
        System.out.println(myQueue.peek());
        System.out.println(myQueue.empty());
        myQueue.pop();
        System.out.println(myQueue.empty());

    }
}

class MyQueue {
    private Stack<Integer> temp;
    private Stack<Integer> queue;
    public MyQueue() {
        //初始化
        temp=new Stack<>();
        queue=new Stack<>();
    }

    public void push(int x) {
        temp.push(x);
    }

    public int pop() {
        //出队时先进行转化
        int val= peek();
        queue.pop();
        return val;
    }

    public int peek() {
        if(!queue.isEmpty())return queue.peek();
        if(temp.isEmpty()) return -1;
        while(!temp.isEmpty()){
            queue.push(temp.pop());
        }
        return queue.peek();
    }

    public boolean empty() {
        return temp.isEmpty()&&queue.isEmpty();
    }
}
